<?php

namespace app\common\model\Member;

use app\common\model\Base;
use think\facade\Config;

class File extends Base
{
    protected $name = 'member_file';

    const TYPE = [
        1 => '照片',
        2 => '阅后即焚',
        3 => '红包照片',
        4 => '审核照片视频',
        5 => '内容照片',
        6 => '评论&报名照片',
        7 => '真人认证',
    ];

    const STATUS = [
        1 => '正常',
        2 => '违规',
    ];

//    public function member()
//    {
//        return $this->belongsTo('app\common\model\member\Member');
//    }

    public function getFileList($condition = [], $field = '*', $order = 'f.id desc', $page = -1)
    {
        if ($page == -1) {
            $page = Config::get('paginate.list_rows');
        }
        $res = $this->alias('f')
            ->where($condition)
            ->join('member m', 'f.member_id=m.id', 'left')
            ->join('photo_pay p_p', 'p_p.file_id=f.id', 'left')
            ->field($field)
            ->order($order);
        if ($page == 0) {
            return $res->select()->toArray();
        } else {
            $res = $res->paginate($page, false, ['query' => request()->param()]);
            $this->page_info = $res;
            return $res->items();
        }
    }


    public function getMemberAblum($member_id, $been_member_id, $condition = [], $field = '*', $order = 'f.id asc', $page = -1)
    {
        if ($page == -1) {
            $page = Config::get('paginate.list_rows');
        }

        $p_json_sql = model('common/photo/Pay')->where(['member_id' => $member_id, 'view_member_id' => $been_member_id])->buildSql();

        $res = $this->alias('f')
            ->where($condition)
            ->join('member m', 'f.member_id=m.id', 'left')
            ->join($p_json_sql . ' p_p', 'p_p.file_id=f.id', 'left')
            ->field($field)
            ->order($order);
//        echo $res->buildSql();die;
        if ($page == 0) {
            return $res->select()->toArray();
        } else {
            $res = $res->paginate($page, false, ['query' => request()->param()]);
            $this->page_info = $res;
            return $res->items();
        }
    }

}